package models

import (
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego"
)

type PqSlTestLibrary struct {
	Id int
	Title string
	Note string
	HardRate float64
	IsOnlineCorrect int
	State int
	PqTestCategoryId int
	PqTestAreaId int
	AreaCode string
	AreaCodes string
	BaseModel
}
func (this *PqSlTestLibrary) ListAll(q ... interface{}) ([]orm.Params,interface{}) {
	var nodes []orm.Params
	model := GetSlaveDb()
	beego.Warning(q)
	//qs := []interface{}{}
	//for k,v := range q{
	//	qs[k] = v
	//}
	model.Raw(`
		select SQL_CALC_FOUND_ROWS stl.*,cate.title as category_title from pq_sl_test_library as stl
		inner join pq_test_category as cate on cate.id = stl.pq_test_category_id
		where stl.state > -1 and cate.lft >= ? and cate.rgt <= ? order by stl.created_time desc
		limit ?,?
	`,q).Values(&nodes)

	var maps []orm.Params
	model.Raw(`select count('stl.*') as amount from pq_sl_test_library as stl
		inner join pq_test_category as cate on cate.id = stl.pq_test_category_id
		where stl.state > -1`).Values(&maps)
	var amount interface{}
	if len(maps) > 0 {
		amount = maps[0]["amount"]
	}

	return nodes,amount
}
